<?php

// 4/10/2010: immanuel192 write this action

if (!defined('EXPONENT')) exit('');

$song_id = -1; $song_col = -1;
$object=null; $song_collection=null;
// first, test song collection 
if (isset($_GET['song_col'])) {
	$_GET['song_col']=intval($_GET['song_col']);
	$song_col=$_GET['song_col'];
	$song_collection = $db->selectObject('present_song_collection','id='.intval($_GET['song_col']));
}
if (!$song_collection)
	validator::failAndReturnToForm('Wrong song collection value.', $_POST);
// test song id
if (isset($_GET['id']))
{
	$_GET['id']=intval($_GET['id']);
	$song_id=$_GET['id'];
	$object = $db->selectObject('present_songs','id='.intval($_GET['id']));
}

// TODO: permission check
//if (($object && exponent_permissions_check('edit',$loc)) || (!$object && exponent_permissions_check('create',$loc))) {

if (($object && exponent_permissions_check('edit',$loc)) || (!$object && exponent_permissions_check('create',$loc))) {
	$form = slide_item::form($object, $song_col);
	//$form->location($loc); no location_data require
	$form->meta('action','save_song');
	$form->meta('module','slidemodule');
	
	
	$template = new template('slidemodule','_form_song_edit');
	$template->assign('is_edit',(isset($object->id)? 1 : 0));
	$template->register_permissions(slidemodule::permissions("",1),$loc);
	$template->assign('form_html',$form->toHTML());
	$template->output();
} else {
	echo SITE_404_HTML;
}

?>
